using System;
using System.Collections.Generic;
using System.Text;
using CodePlex.Resourceful.Amazon.S3;
using CodePlex.Resourceful;

namespace CodePlex.SpaceBlock.FS
{
    public class SunCloudFileSystem : BaseFileSystem, IFileSystem, ISupportsCheckAction, ISupportsTransferWithMetadata
    {

        private readonly S3FileSystem _s3fs;

        public SunCloudFileSystem(S3Connection connection)
        {
            _s3fs = new S3FileSystem(connection);
        }

        

        public Tracer Tracer
        {
            get { return _s3fs.Tracer; }
        }

        public string Caption
        {
            get { return string.Format("Sun Cloud File System - {0}", this.ShortCaption);  }
        }

        public string ShortCaption
        {
            get { return _s3fs.ShortCaption; }
        }

        public bool Exists(Path path)
        {
            return _s3fs.Exists(path);
        }

        public ReadOnlyList<IPathItem> GetItems(Path path)
        {
            return _s3fs.GetItems(path);
        }

        public ReadOnlyList<IFolderItem> GetFolders(Path path)
        {
            return _s3fs.GetFolders(path);
        }

        public ReadOnlyList<IFileItem> GetFiles(Path path)
        {
            return _s3fs.GetFiles(path);
        }

        public IPathItem GetItem(Path path)
        {
            return _s3fs.GetItem(path);
        }

        public void EnsureFolderExists(Path path)
        {
            _s3fs.EnsureFolderExists(path);
        }

        public void EnsureFileExists(Path path)
        {
            _s3fs.EnsureFileExists(path);
        }

        public void Delete(Path path)
        {
            _s3fs.Delete(path);
        }

        public Metadata GetMetadata(Path path)
        {
            return _s3fs.GetMetadata(path);
        }

        public void Transfer(IFileItem source, Path destination, Action<long> bytesTransferred)
        {
            _s3fs.Transfer(source, destination, bytesTransferred);
        }
        public void Transfer(IFileItem source, Path destination, NameValuePairs metadata, Action<long> bytesTransferred)
        {
            _s3fs.Transfer(source, destination, metadata, bytesTransferred);
        }


       
        public bool AllowNewFolder(Path folder)
        {
            return folder.Level >= 0;
        }

        public bool AllowDeleteFolder(Path folder)
        {
            return folder.Level > 0;
        }








        public string GetSignedUrl(RequestStyle style, Path filePath, TimeSpan expirationTimeFromNow)
        {
            return _s3fs.GetSignedUrl(style, filePath, expirationTimeFromNow);
        }
    }
}
